package weekMatch.two_107;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class LeeCode_01 {
    public static void main(String[] args) {
        System.out.println(maximumNumberOfStringPairs(new String[]{"ff", "tx", "qr", "zw", "wr", "jr", "zt", "jk", "sq", "xx"}));
    }
    private static int maximumNumberOfStringPairs(String[] words) {
        Set<String> set = new HashSet<>(Arrays.asList(words));
        int ans = 0;
        for (String word : words) {
            if (charge(word))
                continue;
            String s = new StringBuilder(word).reverse().toString();
            if (set.contains(s))
                ans++;
        }
        return ans / 2;
    }
    private static boolean charge(String s){
        int l = 0, r = s.length() - 1;
        while (l < r){
            if (s.charAt(l) != s.charAt(r)){
                return false;
            }
            l++;
            r--;
        }
        return true;
    }
}